import * as mUtils from "@/util/mUtils";

let studenInfo = [];
//17级网络工程1班
for(let i=1;i <= 10;i++){
    studenInfo.push({
        studentID: (110+i).toString(),
        name: '张三'+i,
        password: '1234',
        school: '湖南科技大学',
        alias: '昵称'+i,
        account: '账号'+i,
        stuNumber: '学号'+i,
        cla: '1班',  //j是班级
        grade: '17级',
        phoNumber: '电话'+i,
        eMail: '邮箱'+i,
        college: '学院1',
        major: '网络工程'
    });
}
//17级网络工程2班
for(let i=11;i <= 20;i++){
    studenInfo.push({
        studentID: (110+i).toString(),
        name: '张三'+i,
        password: '1234',
        school: '湖南科技大学',
        alias: '昵称'+i,
        account: '账号'+i,
        stuNumber: '学号'+i,
        cla: '2班',  //j是班级
        grade: '17级',
        phoNumber: '电话'+i,
        eMail: '邮箱'+i,
        college: '学院1',
        major: '网络工程'
    });
}
//17级信息安全1班
for(let i=21;i <= 30;i++){
    studenInfo.push({
        studentID: (110+i).toString(),
        name: '张三'+i,
        password: '1234',
        school: '湖南科技大学',
        alias: '昵称'+i,
        account: '账号'+i,
        stuNumber: '学号'+i,
        cla: '1班',  //j是班级
        grade: '17级',
        phoNumber: '电话'+i,
        eMail: '邮箱'+i,
        college: '学院1',
        major: '信息安全'
    });
}
//17级信息安全2班
for(let i=31;i <= 40;i++){
    studenInfo.push({
        studentID: (110+i).toString(),
        name: '张三'+i,
        password: '1234',
        school: '湖南科技大学',
        alias: '昵称'+i,
        account: '账号'+i,
        stuNumber: '学号'+i,
        cla: '2班',  //j是班级
        grade: '17级',
        phoNumber: '电话'+i,
        eMail: '邮箱'+i,
        college: '学院1',
        major: '信息安全'
    });
}

//18级网络工程1班
for(let i=41;i <= 50;i++){
    studenInfo.push({
        studentID: (110+i).toString(),
        name: '张三'+i,
        password: '1234',
        school: '湖南科技大学',
        alias: '昵称'+i,
        account: '账号'+i,
        stuNumber: '学号'+i,
        cla: '1班',  //j是班级
        grade: '18级',
        phoNumber: '电话'+i,
        eMail: '邮箱'+i,
        college: '学院1',
        major: '网络工程'
    });
}
//18级网络工程2班
for(let i=51;i <= 60;i++){
    studenInfo.push({
        studentID: (110+i).toString(),
        name: '张三'+i,
        password: '1234',
        school: '湖南科技大学',
        alias: '昵称'+i,
        account: '账号'+i,
        stuNumber: '学号'+i,
        cla: '2班',  //j是班级
        grade: '18级',
        phoNumber: '电话'+i,
        eMail: '邮箱'+i,
        college: '学院1',
        major: '网络工程'
    });
}
//18级信息安全1班
for(let i=61;i <= 70;i++){
    studenInfo.push({
        studentID: (110+i).toString(),
        name: '张三'+i,
        password: '1234',
        school: '湖南科技大学',
        alias: '昵称'+i,
        account: '账号'+i,
        stuNumber: '学号'+i,
        cla: '1班',  //j是班级
        grade: '18级',
        phoNumber: '电话'+i,
        eMail: '邮箱'+i,
        college: '学院1',
        major: '信息安全'
    });
}
//18级信息安全2班
for(let i=71;i <= 80;i++){
    studenInfo.push({
        studentID: (110+i).toString(),
        name: '张三'+i,
        password: '1234',
        school: '湖南科技大学',
        alias: '昵称'+i,
        account: '账号'+i,
        stuNumber: '学号'+i,
        cla: '2班',  //j是班级
        grade: '18级',
        phoNumber: '电话'+i,
        eMail: '邮箱'+i,
        college: '学院1',
        major: '信息安全'
    });
}

export default {
    studentDownload: () => ({ // 下载学生模板
        code: 1,
        msg: "下载成功"
    }),
    teacherDownload: () => ({ // 下载老师模板
        code: 1,
        msg: "下载成功"
    }),
    editStu: () => ({ // 下载老师模板
        code: 1,
        msg: "编辑成功"
    }),
    studentUpload: () => ({ // 上传学生文件
        code: 1,
        msg: "上传成功",
        data: [
            {
                simpleStudentInfo:{
                    studentId: '1',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            },
            {
                simpleStudentInfo:{
                    studentId: '2',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            },
            {
                simpleStudentInfo:{
                    studentId: '3',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            },
            {
                simpleStudentInfo:{
                    studentId: '4',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            },
            {
                simpleStudentInfo:{
                    studentId: '5',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            },
            {
                simpleStudentInfo:{
                    studentId: '6',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            },
            {
                simpleStudentInfo:{
                    studentId: '7',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            },
            {
                simpleStudentInfo:{
                    studentId: '8',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            },
            {
                simpleStudentInfo:{
                    studentId: '9',
                    account: '456',
                    password: '123456',
                    school: '湖南科技大学',
                    name: '小游'
                },
                alias: '小游',
                studentId: '45451',
                major: '计算机科学与工程学院',
                class: '计算机科学与技术四班',
                phone: '123456789',
                eMail: '123456@qq.com'
            }
        ]
    }),
    teacherUpload: () => ({ // 上传老师文件
        code: 1,
        msg: "上传成功"
    }),
    studentPreview: () => ({ // 上传学生文件
        code: 1,
        msg: "预览成功"
    }),
    teacherPreview: () => ({ // 上传老师文件
        code: 1,
        msg: "预览成功"
    }),
    studentInfo: config => {
        const {info} = mUtils.param2Obj(config.url);
        const currPage = JSON.parse(info).currPage;
        const rows = JSON.parse(info).rows;
        const list = studenInfo.filter((item,index) => index < rows * currPage && index >= rows * (currPage - 1))
        return {
            code: 1,
            msg: "获取学生数据成功！",
            data: {
                list: list,
                count: studenInfo.length
            }
        }
    },
    searchStu: config => {
        const {inputValues} = mUtils.param2Obj(config.url);
        // console.log(JSON.parse(inputValues))
        const inputname = JSON.parse(inputValues).inputname;
        const inputstudentID = JSON.parse(inputValues).inputstudentID;
        const currPage = JSON.parse(inputValues).currPage;
        const rows = JSON.parse(inputValues).rows;
        const list = []; //保存查询结果

        //按学生账号ID查询
        if (inputstudentID !== '' && inputname === '') {
            for (let i = 0; i < studenInfo.length; i++) {
                if (studenInfo[i].studentID.indexOf(inputstudentID) >= 0) {
                    list.push(studenInfo[i])
                }
            }
        }
        //按姓名查询
        if (inputstudentID === '' && inputname !== '') {
            for (let i = 0; i < studenInfo.length; i++) {
                if (studenInfo[i].name.indexOf(inputname) >= 0) {
                    list.push(studenInfo[i])
                }
            }
        }
        const list1 = list.filter((item,index) => index < rows * currPage && index >= rows * (currPage - 1))
        return {
            code: 1,
            msg: "查询学生数据成功！",
            data: {
                list:list1,
                count: list.length
            }
        }
    },
    //年级
    getGrade:() => {
        return {
            code: 1,
            msg: "success!",
            data: {
                grade: ['全部','17级','18级']
            }
        }
    },
    //专业
    getMajor:config => {
        const {selectedGrade,currPage,rows} = mUtils.param2Obj(config.url);
        const list = [];
        for (let i = 0; i < studenInfo.length; i++) {
            if (selectedGrade === '全部') {
                list.push(studenInfo[i])
            }else if (studenInfo[i].grade === selectedGrade) {
                list.push(studenInfo[i])
            }
        }
        const list1 = list.filter((item,index) => index < rows * currPage && index >= rows * (currPage - 1))
        return {
            code: 1,
            msg: "success!",
            data: {
                major: ['网络工程','信息安全'],
                list: list1,
                count:list.length
            }
        }
    },
    //班级
    getClass:config => {
        const {selectedGrade,selectedMajor,currPage,rows} = mUtils.param2Obj(config.url);
        const list = [];
        for (let i = 0; i < studenInfo.length; i++) {
            if (selectedGrade === '全部' && studenInfo[i].major === selectedMajor) {
                list.push(studenInfo[i])
            }else if (studenInfo[i].grade === selectedGrade && studenInfo[i].major === selectedMajor) {
                list.push(studenInfo[i])
            }
        }
        const list1 = list.filter((item,index) => index < rows * currPage && index >= rows * (currPage - 1))
        return {
            code: 1,
            msg: 'success!',
            data: {
                class: ['1班','2班'],
                list: list1,
                count: list.length
            }
        }
    },
    //班级查询
    selectClass:config => {
        const {selectedGrade,selectedMajor,selectedClass,currPage,rows} = mUtils.param2Obj(config.url);
        const list = [];
        for (let i = 0; i < studenInfo.length; i++) {
            if (selectedGrade === '全部' && studenInfo[i].major === selectedMajor && studenInfo[i].cla === selectedClass) {
                list.push(studenInfo[i])
            }else if (studenInfo[i].grade === selectedGrade && studenInfo[i].major === selectedMajor && studenInfo[i].cla === selectedClass) {
                list.push(studenInfo[i])
            }
        }
        const list1 = list.filter((item,index) => index < rows * currPage && index >= rows * (currPage - 1))
        return {
            code: 1,
            msg: 'success!',
            data: {
                list: list1,
                count: list.length
            }
        }
    },
    //单个删除学生
    deleteStuRecord:config => {
        const {studentID} = mUtils.param2Obj(config.url);
        studenInfo=studenInfo.filter(item=>item.studentID!==studentID);
        return{
            code: 1,
            msg:'删除学生成功!',
            data:{
                id:{studentID},
                flag : true
            }
        }
    },
    //批量删除学生
    massDeleteStuRecord:config => {
        const {studentIDs} = mUtils.param2Obj(config.url);
        studenInfo = studenInfo.filter(item=>!(JSON.parse(studentIDs).IDs).includes(item.studentID))
        return{
            code: 1,
            msg:'批量删除学生成功!',
            data:{
                flag : true,
            }
        }
    },
    resetPassword:config => {
        const {account} = mUtils.param2Obj(config.url);
        for (let i = 0; i < studenInfo.length; i++) {
            if (studenInfo[i].account === account) {
                studenInfo[i].password = account
            }
        }
        return {
            code: 1,
            msg: '重置密码成功！',
        }
    }
}
